//
//  UIImage+Extension.swift
//  Weibo30LLG
//
//  Created by 李龙 on 16/8/18.
//  Copyright © 2016年 lilong. All rights reserved.
//

import UIKit

extension UIImage {

    // MARK: --等比压缩图片
    func scaleImageWithScaleWidth(scaleWidth: CGFloat) -> UIImage {
        
        let scaleHeight = scaleWidth / self.size.width * self.size.height
        
        let size = CGSize(width: scaleWidth, height: scaleHeight)
        
        //开启图片上下文
        UIGraphicsBeginImageContext(size)
        
        //把图片绘制到指定位置
        self.drawInRect(CGRect(origin: CGPointZero, size: size))
        
        //获取图片
        let scaleImage = UIGraphicsGetImageFromCurrentImageContext()
        
        //关闭图片上下文
        UIGraphicsEndImageContext()
        
        return scaleImage
    }
}

